package com.wwz.frame.controller;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

/**  
* @Description 注解跨域 设置 以及 设置响应头
* @Author wwz
* @Date 2019/08/22 
* @Param   
* @Return   
*/ 
@RestController
@CrossOrigin(origins = "http://localhost:8080",maxAge = 3600)   // 跨域注解
public class CorsController {
    @RequestMapping("/preUser")
    @CrossOrigin()
    public Map<String,String> preUser(){
        Map<String,String> map = new HashMap<>(10);
        map.put("preUser","success");
        return map;
    }
    @RequestMapping("/hello")
    public String index(HttpServletResponse response){
        response.addHeader("Access-Control-Allow-Origin", "http://localhost:8080");
        return "Hello World";
    }
}
